<template>
  <div
    class="cell"
    :class="{ selected: selected }"
    @click="click"
    @touchstart="touchstart"
    @touchend="touchend"
    :style="{ borderRadius: radius }"
  >
    <div class="left-icon">
      <slot name="left-icon"></slot>
    </div>
    <div class="left-wrap">
      <div class="title">{{ title }}</div>
    </div>
    <div class="right-wrap">
      <div class="value" v-if="value">{{ value }}</div>
      <div class="arrow iconfont" v-if="link">&#xe7e7;</div>

      <slot name="right-wrap"></slot>
    </div>
    <div class="line" v-show="line"></div>
  </div>
</template>

<script>
export default {
  name: "Cell",
  props: {
    title: String,
    value: String,
    link: Boolean,
    line: Boolean,
    radius: {
      type: String,
      default: "0px",
    },
  },
  data() {
    return {
      selected: false,
    };
  },
  methods: {
    touchstart() {
      if(this.link) {
        this.selected = true;
      }
      this.$emit("touchstart");
    },
    click() {
      this.$emit("click");
    },
    touchend() {
      if(this.link) {
        this.selected = false;
      }
      this.$emit("touchend");
    },
  },
};
</script>

<style lang="scss" scoped>
.cell {
  width: 100%;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  position: relative;
  background: #fff;
  padding: 0 15px;
  margin: auto;

  &.selected {
    background: #F2F3F5;
  }

  .left-icon {
    line-height: 1;
  }

  .line {
    width: calc(100% - 30px);
    height: 1px;
    background: #f5f5f5;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
  }

  .left-wrap {
    flex: 1;

    .title {
      color: #333;
      font-size: 14px;
    }
  }

  .right-wrap {
    flex: 1;
    text-align: right;
    display: flex;
    align-items: center;
    justify-content: flex-end;

    .value {
      color: #969799;
      font-size: 14px;
    }

    .arrow {
      color: #969799;
      font-size: 14px;
      font-weight: bold;
      margin-left: 8px;
    }
  }
}
</style>
